import { effect } from "./effect.js"

export function watch(source, callback) {
  const getter = typeof source === 'function' ? source : () => source

  let oldValue

  effect(() => {
    const newValue = getter()
    if (oldValue !== newValue) {
      callback(newValue, oldValue)
      oldValue = newValue
    }
  })
}